<%@page contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<t:template>
	<jsp:attribute name="include">
		<script type="text/javascript">
			function reloadTable() {
				var table = $('#logTable').dataTable();
				table.fnReloadAjax();
			}

			function getDetails(id) {
				$.post('<c:url value="/administration/logs/details"/>', {
					"id" : id
				},function(logDetails) {
					var date = new Date(logDetails.millis);
					$("#time").html(date.toLocaleDateString() + " " + date.toLocaleTimeString());
					$("#username").html('<a href="<c:url value="/profile"/>/' + logDetails.username + "\">" + logDetails.username + "</a>");
					$("#type").html(logDetails.marker);
					$("#message").html(logDetails.message);
					$("#level").html(logDetails.level);
					if (logDetails.level == 'FATAL') {
						$("#levelRow").attr('class','error');
					} else if (logDetails.level == 'WARN') {
						$("#levelRow").attr('class','warning');
					} else {
						$("#levelRow").attr('class','');
					}
					if (logDetails.exception != undefined && logDetails.exception != null) {
						$("#exception").html(logDetails.exception);
						$("#stacktrace").html(logDetails.stackTrace);
						$("#exrow1").css('display', 'table-row');
						$("#exrow2").css('display', 'table-row');
					} else {
						$("#exrow1").css('display', 'none');
						$("#exrow2").css('display', 'none');
					}
					$("#logDetailsModal").modal('show');
				},"json");
			}

			var serverDatas = [ "markerName" ];

			function pageInit() {
				createDataTable("logTable", '<c:url value="/administration/logs/json"/>', [ timestampColDef(0, "millis"),
						linkFormattedColDef(1, '<c:url value="/profile"/>', "username"), colDef(2, "marker"), colDefNotSortable(3, "message"), {
							"sName" : "details",
							"aTargets" : [ 4 ],
							"bSortable" : false,
							"mData" : function(data, type, full) {
								return '<a onclick="getDetails(' + data.id + ');"/>Részletek</a>';
							}
						} ], true, "desc");
				var selectGen = $('#selectGen');
				$("#logTable_filter>label>input").replaceWith(selectGen.html());
				selectGen.remove();
			};
		</script>
	</jsp:attribute>
	<jsp:attribute name="pagetitle">
      Felhasználók kezelése
    </jsp:attribute>
	<jsp:body>
		<div id="selectGen">
			<select id="markerName" name="markerName" data-size="7"
				onchange="reloadTable()">
				<option value="">Mind</option>
				${markers }
			</select>
		</div>
    	<table id="logTable">
		    <thead>
				<tr>
					<th>Időpont</th>
					<th>Felhasználó</th>
					<th>Típus</th>
					<th>Üzenet</th>
					<th>&nbsp;</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<th>Időpont</th>
					<th>Felhasználó</th>
					<th>Típus</th>
					<th>Üzenet</th>
					<th>&nbsp;</th>
				</tr>
			</tfoot>
    	</table>
    	
    	<div class="modal hide fade" id="logDetailsModal">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h3>Részletek</h3>
			</div>
			<div class="modal-body">
				<table class="table table-striped table-bordered table-hover">
					<tr id="levelRow">
						<th>Súlyosság</th>
						<td id="level"></td>
					</tr>
					<tr>
						<th>Időpont</th>
						<td id="time"></td>
					</tr>
					<tr>
						<th>Felhasználó</th>
						<td id="username"></td>
					</tr>
					<tr>
						<th>Típus</th>
						<td id="type"></td>
					</tr>
					<tr>
						<th>Üzenet</th>
						<td id="message"></td>
					</tr>
					<tr id="exrow1">
						<th>Kivétel</th>
						<td id="exception"></td>
					</tr>
					<tr id="exrow2">
						<th>StackTrace</th>
						<td id="stacktrace"></td>
					</tr>
				</table>
			</div>
			<div class="modal-footer">
				<div class="btn-group">
					<a href="#" class="btn" data-dismiss="modal">Bezárás</a>
				</div>
			</div>
		</div>
    </jsp:body>
</t:template>